package com.gemme.gemme.view;

import android.content.Context;
import android.view.View;

import com.gemme.gemme.R;

public class GoodsSatateDialog {
    BottomDialog dialog;
    private OnChangeLIstener onChangeLIstener;

    public void showDialog(Context mContext){
//new int[]{R.id.close}
        dialog = new BottomDialog(mContext, R.layout.goods_state_dialog,
                new int[]{R.id.close});

        dialog.show();
        initView();
        dialog.setOnBottomItemClickListener(new BottomDialog.OnBottomItemClickListener() {
            @Override
            public void onBottomItemClick(BottomDialog dialog, View view) {
                switch (view.getId()) {
                    case R.id.close:
                        dialog.dismiss();
                        break;

                }
            }
        });
    }

    boolean isHaveGoods = false;
    RoundCheckBox cb_no_goods;
    RoundCheckBox cb_has_goods;
    private void initView() {
        View view = dialog.getView();
         cb_no_goods = dialog.findViewById(R.id.cb_no_goods);
         cb_has_goods = dialog.findViewById(R.id.cb_has_goods);

        changeState();

        cb_no_goods.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_no_goods.isChecked();
                isHaveGoods = !checked;
                changeState();
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
        cb_has_goods.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                boolean checked = cb_has_goods.isChecked();
                isHaveGoods = checked;
                changeState();
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });

    }

    private void changeState() {
        cb_no_goods.setChecked(!isHaveGoods);
        cb_has_goods.setChecked(isHaveGoods);
    }

    public void setOnChangeLIstener(OnChangeLIstener onChangeLIstener){

        this.onChangeLIstener = onChangeLIstener;
    }

    public boolean getState(){
        return isHaveGoods;
    }

}
